home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
011
/
lmouse.arc
/
LSET.C
< prev
next >
Wrap
Text File
|
1986-06-14
|
17KB
|
659 lines
/* By Mark E. Johnson. 2272-F Benson Ave. St. Paul MN 55116 */
/* COMPILE with Lattice Small Model compiler */
/* LINK C+LSET+KEY_SCAN, LSET,, LC */
#include <stdio.h> /* 6/14/86 */
#include <dos.h>
#define TRUE 1
#define FALSE 0
#define VOID int /* Makes it look like a better compiler */
union REGS regs; /* word structure for registers */
struct SREGS sregs; /* byte structure for registers */
typedef struct { /* Long Pointer for Small Model */
unsigned int offset;
unsigned int segment;
} lptr;
struct config_string {
char press1[60],
release1[60],
press2[60],
release2[60],
press3[60],
release3[60],
up[8],
down[8],
left[8],
right[8];
/* The following must be set to the length of the above strings */
int Lpress1, /* length of press1 */
Lrel1,
Lpress2,
Lrel2,
Lpress3,
Lrel3,
Lup,
Ldown,
Lleft,
Lright;
};
struct config_string mousekeys;
int x_scale, y_scale, h;
int quit = 0;
int videoseg; /* points to $B000 or $B800 for color or mono */
int line, column;
int key_scan(); /* from KEY_SCAN.ASM */
main()
{
unsigned i, d, noofbuttons;
int status;
int horiz, vert;
int buttonstatus, buttonpresscount;
char c;
setvideoseg();
clrs();
flush_kbd();
writeat( 6,0,7," Mouse Forward"); /* 6 */
writeat( 7,0,7," Mouse Backward"); /* 7 */
writeat( 8,0,7," Mouse Left"); /* 8 */
writeat( 9,0,7," Mouse Right"); /* 9 */
writeat(10,0,7," EXIT");
writeat(11,0,7," Button 1 Down"); /* 11 */
writeat(12,0,7," Button 1 Up"); /* 12 */
/* writeat(13,0,7," LOAD"); */
writeat(14,0,7," Button 2 Down"); /* 14 */
writeat(15,0,7," Button 2 Up"); /* 15 */
/* writeat(16,0,7," SAVE"); */
writeat(17,0,7," Button 3 Down"); /* 17 */
writeat(18,0,7," Button 3 Up"); /* 18 */
writeat(20,0,7," X scale 1-9"); /* 20 */
writeat(21,0,7," Y scale 1-9"); /* 21 */
writeat(1,1,0x70,"Please wait...");
flagreset(&status, &noofbuttons);
setmousemode(0);
writeat(1,1,7," ");
showcursor();
horiz = 0;
vert = 0;
quit = 0;
for( ; quit != 1 ;)
{
buttonstatus = 0; /* left button */
WAI("Waiting for Button");
while (buttonstatus == 0)
getposbut(&buttonstatus, &horiz, &vert);
for (i=1; i < 10000; i++) /* Debounce delay */
h=i;
if (buttonstatus > 0)
{
writeat(1,1,0x70,"Enter Sequence...");
switch(vert)
{
case 48 :
mousekeys.Lup = kbd_gets(6,22,mousekeys.up,8);
break;
case 56 :
mousekeys.Ldown = kbd_gets(7,22,mousekeys.down,8);
break;
case 64 :
mousekeys.Lleft = kbd_gets(8,22,mousekeys.left,8);
break;
case 72 :
mousekeys.Lright = kbd_gets(9,22,mousekeys.right,8);
break;
case 80 : quit = 1;
break;
case 88 :
mousekeys.Lpress1 = kbd_gets(11,22,mousekeys.press1,60);
break;
case 96 :
mousekeys.Lrel1 = kbd_gets(12,22,mousekeys.release1,60);
break;
case 104 : /* load */
break;
case 112 :
mousekeys.Lpress2 = kbd_gets(14,22,mousekeys.press2,60);
break;
case 120 :
mousekeys.Lrel2 = kbd_gets(15,22,mousekeys.release2,60);
break;
case 128 :
/* save */
break;
case 136 :
mousekeys.Lpress3 = kbd_gets(17,22,mousekeys.press3,60);
break;
case 144 :
mousekeys.Lrel3 = kbd_gets(18,22,mousekeys.release3,60);
break;
case 160 :
gotoxy(20,22);
writeat(20,22,0x70," X scale ");
x_scale = getche() & 0x0F;
writeat(20,23,7," ");
break;
case 168 :
gotoxy(21,22);
writeat(21,22,0x70," Y scale ");
y_scale = getche() & 0x0F;
writeat(21,23,7," ");
} /* switch */
writeat(1,1,7," ");
setcursorpos(horiz, vert);
showcursor();
} /* if buttonstatus */
}
WAI("Resetting Mouse");
hidecursor();
flagreset(&status, &noofbuttons);
WAI("Programming Mouse");
setkeybase(3,&mousekeys,x_scale,y_scale);
setmousemode(1);
gotoxy(24,0);
}
VOID scan_out(c, scan)
char c;
int scan;
{
if (c == 0) /* extended code follows */
switch(scan)
{
case 0x47 : vputs(0x70, "<HOME>");
break;
case 0x48 : vputs(0x70, "<UP>");
break;
case 0x49 : vputs(0x70, "<PgUp>");
break;
case 0x4B : vputs(0x70, "<LEFT>");
break;
case 0x4D : vputs(0x70, "<RIGHT>");
break;
case 0x4F : vputs(0x70, "<End>");
break;
case 0x50 : vputs(0x70, "<DOWN>");
break;
case 0x51 : vputs(0x70, "<PgDwn>");
break;
case 0x52 : vputs(0x70, "<Ins>");
break;
case 0x53 : vputs(0x70, "<Del>");
break;
default : vputc(0x70, c);
}
else
if ( c < 0x20 ) /* Control Character */
{
vputc(0x70,'^');
vputc(0x70,c+0x40);
}
}
int kbd_gets(x, y, string, maxlen)
int x, y;
char *string;
int maxlen;
{
int c, scan, len, button, buttonstatus, horiz, vert;
int hold_vertical, i, h;
vgotoxy(x, y);
clreol();
len = 0;
getposbut(&buttonstatus, &horiz, &hold_vertical);
do
{
while(key_scan() == 0 && buttonstatus == 0)
getposbut(&buttonstatus, &horiz, &vert);
if (buttonstatus != 0)
{
WAI("Button Depressed");
c = 0;
scan = 0x3b;
vputs(0x70, "< Terminated >");
for (i=1; i < 10000; i++)
h=i; /* debounce */
}
else
{
WAI("Character Entered");
scan_kbd(&c, &scan);
}
if (c < 0x20) /* Control character */
scan_out(c,scan);
else
vputc(0x70,c);
flush_kbd();
if (scan != 0x3B)
{
*string++ = c;
*string++ = scan;
len += 2;
if (len > maxlen)
scan = 0x3B;
}
} while(scan != 0x3B);
return(len);
}
/************* MOUSE FUNCTIONS ****************/
VOID flagreset(mousestatusptr, numberofbuttonsptr)
int *mousestatusptr, *numberofbuttonsptr;
/* Output AX --> Mouse status
0 (FALSE) : mouse not installed
-1 (TRUE) : Mouse installed
BX --> Number of buttons */
{
regs.x.ax = 0;
int86(0x33,®s,®s);
*mousestatusptr = regs.x.ax;
*numberofbuttonsptr = regs.x.bx;
}
VOID showcursor()
{
regs.x.ax = 1;
int86(0x33,®s,®s);
}
VOID hidecursor()
{
regs.x.ax = 2;
int86(0x33,®s,®s);
}
VOID getposbut(buttonstatus, horizontal, vertical)
int *buttonstatus, *horizontal, *vertical;
/* Output buttonstatus --> Button pressed
horizontal --> horizontal cursor position
vertical --> Vertical cursor position */
{
regs.x.ax = 3;
int86(0x33,®s,®s);
*buttonstatus=regs.x.bx;
*horizontal =regs.x.cx;
*vertical =regs.x.dx;
}
VOID setcursorpos(horizontal,vertical)
int horizontal, vertical;
{
regs.x.ax=4;
regs.x.cx=horizontal;
regs.x.dx=vertical;
int86(0x33,®s,®s);
}
VOID getbutpres(button,buttonstatus,buttonpresscount,horizontal,vertical)
int button, *buttonstatus, *buttonpresscount, *horizontal, *vertical;
/* Input button --> Button to check on
Output buttonstatus --> Current Button pressed
buttonpresscount number of button presses
horizontal --> horizontal cursor position
vertical --> Vertical cursor position */
{
regs.x.ax=5;
regs.x.bx=button;
int86(0x33,®s,®s);
*buttonstatus = regs.x.ax;
*buttonpresscount = regs.x.bx;
*horizontal = regs.x.cx;
*vertical = regs.x.dx;
}
VOID getbutrel(button,buttonstatus,buttonreleasecount,horizontal,vertical)
int button, *buttonstatus, *buttonreleasecount, *horizontal, *vertical;
/* Input button --> Button to check on
Output buttonstatus --> Current button pressed
buttonpresscount number of button releases
horizontal --> horizontal cursor position
vertical --> Vertical cursor position */
{
regs.x.ax=6;
regs.x.bx=button;
int86(0x33,®s,®s);
*buttonstatus = regs.x.ax;
*buttonreleasecount = regs.x.bx;
*horizontal = regs.x.cx;
*vertical = regs.x.dx;
}
VOID sethorizontallimits(minpos, maxpos)
int minpos, maxpos;
{
regs.x.ax=7;
regs.x.cx=minpos;
regs.x.dx=maxpos;
int86(0x33,®s,®s);
}
VOID setverticallimits(minpos, maxpos)
int minpos, maxpos;
{
regs.x.ax=8;
regs.x.cx=minpos;
regs.x.dx=maxpos;
int86(0x33,®s,®s);
}
VOID readmotioncounters(horizontal, vertical)
/* returns the number of steps since last call */
int *horizontal, *vertical;
{
regs.x.ax=11;
int86(0x33,®s,®s);
*horizontal = regs.x.cx;
*vertical = regs.x.dx;
}
VOID setmickeysperpixel(horpix, verpix)
unsigned int horpix, verpix;
{
regs.x.ax=15;
regs.x.cx=horpix;
regs.x.dx=verpix;
int86(0x33,®s,®s);
}
int getmousemode() /* 0 = mousebase, 1 = keybase, 2 = inactive */
{
regs.x.ax=32;
int86(0x33,®s,®s);
return(regs.x.bx);
}
VOID setmousemode(mode)
int mode;
{
regs.x.ax=33;
regs.x.bx=mode;
int86(0x33,®s,®s);
}
VOID setkeybase(mode,keys,x,y)
/* set KEYBASE mode, 0 = use specified config, 1 = default */
int mode;
struct config_string *keys;
int x, y;
{
int dataseg;
struct keytype {
int pbut1len; lptr pbut1ptr;
int rbut1len; lptr rbut1ptr;
int pbut2len; lptr pbut2ptr;
int rbut2len; lptr rbut2ptr;
int pbut3len; lptr pbut3ptr;
int rbut3len; lptr rbut3ptr;
int uplen; lptr upptr;
int downlen; lptr downptr;
int leftlen; lptr leftptr;
int rightlen; lptr rightptr;
int xscale, yscale;
};
struct keytype keybase;
segread(&sregs); /* Read our current segment registers */
dataseg=sregs.ds;
if (mode != 1)
{
keybase.pbut1len = keys->Lpress1;
keybase.pbut1ptr.offset = (int) &(keys->press1);
keybase.pbut1ptr.segment = dataseg;
keybase.rbut1len = keys->Lrel1;
keybase.rbut1ptr.offset = (int) &(keys->release1);
keybase.rbut1ptr.segment = dataseg;
keybase.pbut2len = keys->Lpress2;
keybase.pbut2ptr.offset = (int) &(keys->press2);
keybase.pbut2ptr.segment = dataseg;
keybase.rbut2len = keys->Lrel2;
keybase.rbut2ptr.offset = (int) &(keys->release2);
keybase.rbut2ptr.segment = dataseg;
keybase.pbut3len = keys->Lpress3;
keybase.pbut3ptr.offset = (int) &(keys->press3);
keybase.pbut3ptr.segment = dataseg;
keybase.rbut3len = keys->Lrel3;
keybase.rbut3ptr.offset = (int) &(keys->release3);
keybase.rbut3ptr.segment = dataseg;
keybase.uplen = keys->Lup;
keybase.upptr.offset = (int) &(keys->up);
keybase.upptr.segment = dataseg;
keybase.downlen = keys->Ldown;
keybase.downptr.offset = (int) &(keys->down);
keybase.downptr.segment = dataseg;
keybase.leftlen = keys->Lleft;
keybase.leftptr.offset = (int) &(keys->left);
keybase.leftptr.segment = dataseg;
keybase.rightlen = keys->Lright;
keybase.rightptr.offset = (int) &(keys->right);
keybase.rightptr.segment = dataseg;
keybase.xscale = x;
keybase.yscale = y;
regs.x.dx = (int) &keybase;
sregs.es = dataseg;
}
regs.x.ax=35;
regs.x.bx=mode;
int86(0x33,®s,®s);
}
/****************** Very Low Level BIOS CALLS ****************/
VOID setmode(mode) /* 640x200 = 2, 80x24 text = 6 */
char mode;
{
regs.h.ah=0;
regs.h.al=mode;
int86(0x10,®s,®s);
}
VOID scan_kbd(c,scan) /* Returns Ascii Key code and/or scan code */
int *c, *scan;
{
regs.h.ah = 0;
int86(0x16, ®s, ®s);
*scan = regs.h.ah;
*c = regs.h.al; /* zero if not Ascii */
}
VOID flush_kbd() /* Make sure keyboard buffer is clear */
{
int c,scan;
while( key_scan() )
{
scan_kbd(c,scan);
writeat(2,50,0x07,"Flush");
}
}
VOID gotoxy(row, col)
int row, col;
{
regs.h.dh = row;
regs.h.dl = col;
regs.h.bh = 0;
regs.h.ah = 2;
int86(0x10, ®s, ®s);
}
VOID get_cur(row, col)
int *row, *col;
{
regs.h.bh = 0;
regs.h.ah = 3;
int86(0x10, ®s, ®s);
*row=regs.h.dh;
*col=regs.h.dl;
return;
}
int colormonitor() /* Returns TRUE if a Color monitor is installed */
{
regs.h.ah = 15;
int86(0x10,®s,®s);
if (regs.h.al == 7)
return(FALSE);
else return(TRUE);
}
VOID setvideoseg()
{
if (colormonitor() == TRUE)
{
videoseg = 0xB800;
}
else
videoseg = 0xB000;
}
VOID writeat(x, y, mode, s) /* MODE VALUES
Norm: 0x07 Rev: 0x70 Hi: 0x0F
RevHi: 0x78 Blink: 0x87
*/
int x, y, mode;
char *s;
{
vgotoxy(x, y);
vputs(mode,s);
}
VOID vputc(mode,c)
int mode;
char c;
{
char m, c2;
int offset;
m = mode;
c2 = c;
offset = 2*(line*80+column);
poke(videoseg, offset, &c2, 1);
poke(videoseg, offset+1, &m, 1);
column++;
}
VOID vputs(mode,s)
int mode;
char *s;
{
while(*s)
vputc(mode,*s++);
}
VOID vgotoxy(x, y)
int x, y;
{
line = x;
column = y;
}
VOID clrs()
{
int i;
vgotoxy(0, 0);
for(i=0; i <= 24; i++)
{
vgotoxy(i,0);
clreol();
}
line = 0;
column = 0;
}
VOID clreol()
{
int i, x, y;
x = line;
y = column;
for(i=column; i <= 79; i++)
vputc(0x07,' ');
line = x;
column = y;
}
VOID WAI(s) /* Where Am I */
char *s;
{
int x, y;
x = line;
y = column;
vgotoxy(1,50);
vputs(0x07," ");
vgotoxy(1,50);
vputs(0x07,s);
line = x;
column = y;
}